package com.yh.inter;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author by 张晨光
 * @date 2024/1/18 14:44
 */

public class MyIntercepter implements HandlerInterceptor {
    //Alt+Insert键,重写3个方法;

    /**
     * 执行目标方法之前进行拦截
     *          返回值： true 放行  false 拦截不放行
     */
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("绑匪1拦截...");
        System.out.println("有关系...");
        //return false;
        return true;
    }

    /**
     * 在目标方法执行之后，进行增强
     */
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("拦截1之后");
    }

    /**
     * 渲染之后，释放资源
     */
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("资源1释放...");
    }
}
